package org.aphasia4j.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.OneToMany;

/**
 * @author hillger.t
 */
@Entity
public class Word extends Model {
  @Column(nullable = false)
  private String name;

  @JoinTable(name = "wordcategory")
  @JoinColumn(name = "wordid")
  @OneToMany(targetEntity = Category.class, fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
  private List<Category> categories = new ArrayList<Category>();

  @OneToMany(targetEntity = Picture.class, fetch = FetchType.LAZY)
  private List<Picture> pictures;

  @Lob
  @Basic(fetch = FetchType.LAZY)
  private byte[] sound;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public List<Category> getCategories() {
    return categories;
  }

  public void setCategories(List<Category> categories) {
    this.categories = categories;
  }

  public void addCategory(Category category) {
    this.categories.add(category);
  }

  public byte[] getSound() {
    return sound;
  }

  public List<Picture> getPictures() {
    return pictures;
  }

  public void setPictures(List<Picture> pictures) {
    this.pictures = pictures;
  }

  public void setSound(byte[] sound) {
    this.sound = sound;
  }

  public boolean isSoundAvailable() {
    return null != this.sound;
  }
}
